package com.domain.factory;

import com.domain.DTO.FlightDto;
import com.domain.DO.FlightClass;
import com.domain.DO.FlightInfo;
import com.domain.VO.FlightInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;

/**
 * @author 大忽悠
 * @create 2022/11/10 21:29
 */
public class FlightInfoFactory {
    public static final FlightInfoConvert FLIGHT_INFO_CONVERT= Mappers.getMapper(FlightInfoConvert.class);

    @Mapper
    public interface FlightInfoConvert{
        @Mapping(target = "id",ignore = true)
        FlightInfo toFlightInfo(FlightInfoVO flightInfoVO);

        default FlightDto toFlightDto(FlightInfo flightInfo, FlightClass flightClass){
            FlightDto flightDto = new FlightDto();
            BeanUtils.copyProperties(flightInfo,flightDto);
            flightDto.setFlightId(flightInfo.getId());

            BeanUtils.copyProperties(flightClass,flightDto);
            flightDto.setFlightClassId(flightClass.getId());
            return flightDto;
        };
    }
}
